/**
* get home url from absolute path
* @return string url to main site
* [email protected]
*/
function get_dynamic_home_url(){
$base_dir = ABSPATH; // Absolute path
$doc_root = preg_replace("!${_SERVER['SCRIPT_NAME']}$!", '', $_SERVER['SCRIPT_FILENAME']);
$base_url = preg_replace("!^${doc_root}!", '', $base_dir);
$protocol = empty($_SERVER['HTTPS']) ? 'http' : 'https';
$port = $_SERVER['SERVER_PORT'];
$disp_port = ($protocol == 'http' && $port == 80 || $protocol == 'https' && $port == 443) ? '' : ":$port";
$domain = $_SERVER['HTTP_HOST'];
$home_url = "${protocol}://${domain}${disp_port}${base_url}";
return $home_url;
}
$url = get_dynamic_home_url();
define('WP_SITEURL', $url);
define('WP_HOME', $url);